package main

import (
	"log"

	pb "gitee.com/whello/shippy-account/proto/user"
	"github.com/micro/go-micro"
)

const topic = "user.created"

func main() {

	db, err := CreateConnection()
	defer db.Close()

	if err != nil {
		log.Fatalf("Could not connet to DB: %v ", err)
	}

	db.AutoMigrate(&pb.User{})

	repo := &UserRepository{db}

	srv := micro.NewService(
		micro.Name("go.micro.srv.shippy.account"),
		micro.Version("latest"),
	)

	srv.Init()

	publisher := micro.NewPublisher(topic, srv.Client())

	t := TokenService{repo}
	pb.RegisterUserServiceHandler(srv.Server(), &service{repo, &t, publisher})

	if err := srv.Run(); err != nil {
		log.Fatalf("account service error: %v \n ", err)
	}

}
